package com.boarsoft.message.test.activemq.amqp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.boarsoft.message.activemq.AmqClientEx;
import com.boarsoft.message.bean.Message;

@Deprecated
public class ListenerTest2 {
	private static final Logger log = LoggerFactory.getLogger(ListenerTest2.class);
	private static ClassPathXmlApplicationContext ctx;

	public static void main(String[] args) {
		ctx = new ClassPathXmlApplicationContext("classpath:conf/context.xml");
		System.out.println("Startup ".concat(ctx.isRunning() ? "successfully." : "failed."));
		
		final AmqClientEx client = (AmqClientEx) ctx.getBean("amqClient1");

		// Destination destination = session.createQueue("sms_debit");
		// final MessageConsumer consumer = session.createConsumer(destination);
		System.out.println("Waiting for messages...");
		int i = 0;
		while (true) {
			try {
				Message m = client.get("sms_debit");
				log.info("Received text message {}", m);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			i++;
			if (i >= 300000) {
				break;
			}
		}
		log.info("Reach {}", i);

		ctx.close();
	}
}